<? include("PT_BR.php"); ?>
<html>
<head>
<title>
<?echo DETERMINANTE_MSG_03;?>
</title>
</head><body>
<?
    echo "<b>".DETERMINANTE_MSG_03."</b><br><br>".DETERMINANTE_MSG_04." ".$dim;
    echo "<br><br>";
    echo "<p align=left><b>".(DETERMINANTE_MSG_05)."</b> <br>";
    echo "<table cellspacing=\"1\" bgcolor=\"000000\">";
    for ($i=0; $i<$dim; $i++) {
        echo "<tr>";
        for ($j=0; $j<$dim; $j++) {
                echo "<td bgcolor=\"FFFFFF\" height=\"25\" width=\"25\" align=\"center\">".$A[$i][$j]."</td>";
        }
        echo "</tr>";
    }
    echo "</table>";
    echo "<br>";
    //echo "<b>Fator de correção do determinante:</b>";
    //echo "<br>";
    //$d = 1;
    //echo "d=1";
    //echo "<br>";
    //triangularização
    $det = 1;
    for ($k=0; $k<$dim-1; $k++) {
        for ($i=$k+1; $i<$dim; $i++) {
            if ($A[$k][$k]==0) {	// pivo se anula	
                    $maior = abs($A[$k][$k]);
                    for ($cont=$k+1; $cont<$dim; $cont++) {
                            if (abs($A[$cont][$k]) > $maior) {
                                $maior = abs($A[$cont][$k]);
                                $indice = $cont;
                            }
                    }
                    $troca = $indice + 1;
                    for ($l=0; $l<=$dim; $l++) { //troca de linha
                        $aux2=$A[$k][$l];
                        $A[$k][$l]=$A[$indice][$l]; 
                        $A[$indice][$l]=$aux2;
                    }
                    $det = -$det;
                } // end if
                $M[$i][$k]=-$A[$i][$k]/$A[$k][$k];
                for ($j=0; $j<$dim; $j++) { 
                    $A[$i][$j]+=$M[$i][$k]*$A[$k][$j];
                }
        }
        echo $k+1;
        echo "<sup>o</sup> ".(DETERMINANTE_MSG_09)."";
        echo "<table cellspacing=\"0\" bgcolor=\"FFFFFF\" width=\"".($dim*25+250)."\">";
        echo "<tr><td width=\"".($dim*25+10)."\">";
        echo "<table cellspacing=\"1\" bgcolor=\"000000\">";
        for ($cont=0; $cont<$dim; $cont++) {
                echo "<tr>";
                for ($cont1=0; $cont1<$dim; $cont1++) {
                    echo "<td bgcolor=\"FFFFFF\" height=\"25\" width=\"25\" align=\"center\">".round($A[$cont][$cont1],1)."</td>";
                }
            echo "</tr>";
        }
        echo "</table></td><td width=\"".(($dim*25+300)-($dim*25+10))."\">";
        echo "<table cellspacing=\"0\" bgcolor=\"000000\" width=\"100%\">";
        for ($cont=0; $cont<$dim; $cont++)
        {
            echo "<tr>";
            echo "<td bgcolor=\"FFFFFF\" height=\"25\" width=\"25\" align=\"left\">";
                if ($cont>=$k+1) {
                echo "L<sub>".($cont+1)."</sub> = L<sub>".($cont+1)."</sub> - a<sub>".($cont+1)."$cont</sub>/a<sub>$cont$cont</sub> * L<sub>$cont</sub>";
                //	echo " ";
                }
            echo "</td>";
            echo "</tr>";
        }

        echo "</table></td></tr></table><br>";
    }

    for ($i=0; $i<$dim; $i++) {
            $det = $det * $A[$i][$i];
    }
    echo "Det(A) = ".$det;
?>
</body></html>
